<template>
  <div class="main-header">
    <div class="header-left">
      <span>{{ pageName }}</span>
    </div>
    <div class="header-right">
      <ul class="">
        <li class="bell-wrapper">
          <i class="bell-icon"> </i>
        </li>
        <li class="user-info-wrapper">
          <i class="user-icon"> </i>
          <span class="user-name">{{ ' ' + userName }}</span>
        </li>
        <li class="exit-wrapper" @click="exit()"><i class="exit-icon"></i></li>
      </ul>
    </div>
  </div>
</template>

<script>
import NoticeBox from './noticeBox';
import UserInfoBox from './userInfoBox';
import { mapState, mapGetters, mapActions } from 'vuex';
export default {
  components: { NoticeBox, UserInfoBox },
  data() {
    return {};
  },
  computed: {
    ...mapState('base', ['isFromExamWeb']),
    ...mapGetters('user', ['userName']),
    pageName() {
      return this.$route.path.includes('schoolManage')
        ? '学校管理'
        : '权限管理';
    },
  },

  methods: {
    ...mapActions('school', ['RESET_SCHOOL']),
    exit() {
      // 清除所有模块的状态（包括 sessionStorage）
      this.$store.dispatch('clearAllState');
      
      if (this.isFromExamWeb) window.close();
      else
        this.$router.push({
          path: '/login',
        });
    },
  },
};
</script>

<style lang="less" scoped>
.main-header {
  box-sizing: border-box;
  height: 100%;
  width: 100%;
  padding: 0 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-image: linear-gradient(#fff, #fff), linear-gradient(#fff, #fff);
  box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, 0.08);

  .header-left {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 2px;
    color: #666;
  }

  .header-right {
    position: relative;
    ul {
      display: flex;
      align-items: center;
    }
    ul > li {
      margin-right: 13px;
      cursor: pointer;
    }

    .bell-wrapper {
      .notice-box {
        display: none;
      }
      &:hover {
        .notice-box {
          display: block;
        }
      }
      .bell-icon {
        width: 16px;
        height: 20px;
        background: url('@/assets/image/main-header/通知信息.png') center
          no-repeat;
        position: relative;
      }
      .new-notice-icon {
        width: 6px;
        height: 6px;
        background-color: #1875f0;
        border-radius: 50%;
        position: absolute;
        right: 0;
        top: 0;
      }
    }

    .user-info-wrapper {
      .user-icon {
        width: 24px;
        height: 22px;
        background: url('@/assets/image/main-header/添加成员.png') center
          no-repeat;
        &:hover {
          .user-info-box {
            display: block;
          }
        }
        .user-info-box {
          display: none;
        }
      }
      .user-name {
        cursor: default;
        position: relative;
        top: -4px;
      }
    }

    .exit-icon {
      width: 21px;
      height: 20px;
      background: url('@/assets/image/main-header/退出.png') center no-repeat;
      position: relative;
      top: 3px;
    }
  }
}
</style>
